//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//
package com.allchips.pin.util;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;

import java.util.List;
import java.util.Map;

@JsonInclude(Include.NON_NULL)
public class Page<T> extends BaseEntity {
    public static final int DEFAULT_PAGE_SIZE = 20;
    private int pageNo = 1;
    private int pageSize = 20;
    private long totalCount = -1L;
    private int totalPageCount = -1;
    private T param;
    private Map<String, Object> extraParam;
    private List<T> result;

    public Page() {
    }

    public Page(int pageNo, int pageSize) {
        this.pageNo = pageNo;
        this.pageSize = pageSize;
    }

    public int getPageNo() {
        return this.pageNo;
    }

    public void setPageNo(int pageNo) {
        this.pageNo = pageNo;
    }

    public int getPageSize() {
        return this.pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
        this.computeTotalPage();
    }

    public long getTotalCount() {
        return this.totalCount;
    }

    public int getTotalPageCount() {
        return this.totalPageCount;
    }

    public void setTotalCount(long totalCount) {
        this.totalCount = totalCount;
        this.computeTotalPage();
    }

    protected void computeTotalPage() {
        if (this.getPageSize() > 0 && this.getTotalCount() > -1L) {
            this.totalPageCount = (int) (this.getTotalCount() % (long) this.getPageSize() == 0L ? this.getTotalCount() / (long) this.getPageSize() : this.getTotalCount() / (long) this.getPageSize() + 1L);
        }

    }

    public T getParam() {
        return this.param;
    }

    public void setParam(T param) {
        this.param = param;
    }

    public Map<String, Object> getExtraParam() {
        return this.extraParam;
    }

    public void setExtraParam(Map<String, Object> extraParam) {
        this.extraParam = extraParam;
    }

    public List<T> getResult() {
        return this.result;
    }

    public void setResult(List<T> result) {
        this.result = result;
    }

    @JsonIgnore
    public int getStart() {
        return (this.pageNo - 1) * this.pageSize;
    }

    @JsonIgnore
    public int getEnd() {
        return this.pageNo * this.pageSize - 1;
    }

    public int getCurrentPageNo() {
        return this.pageNo;
    }
}
